using Godot;
using System;

public partial class ExperienceBar : CanvasLayer
{
	[Export]
	ExperienceManager experienceManager;

	private ProgressBar progressBar;

	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		experienceManager.ExperienceUpdated += OnExperienceUpdated;
		progressBar = GetNode<ProgressBar>("MarginContainer/ProgressBar");

		progressBar.Value = 0;
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
	}

	public void OnExperienceUpdated(int currentExperience,int targetExperience){
		var percent = (float)currentExperience/targetExperience;
		GD.Print("经验:",currentExperience,"/",targetExperience,";rate:",percent);
		progressBar.Value = percent;
	}
}
